package com.nowadays.mobile.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.preference.PreferenceManager;

import com.nowadays.mobile.MainApplication;

public class SettingInfo {
  private static SharedPreferences sp;
  private static Editor editor;

  private static Context context;
  private volatile static SettingInfo instance;

  public static final int STEP = 1;


  private SettingInfo() {
    context = MainApplication.getContext();
    sp = PreferenceManager.getDefaultSharedPreferences(context);
    editor = sp.edit();
  }

  public static SettingInfo getInstance() {
    if (instance == null) {
      synchronized (SettingInfo.class) {
        if (instance == null) {
          instance = new SettingInfo();
        }
      }
    }
    return instance;
  }


  public int getFocusTime() {
    int saveTime = sp.getInt("setting_focus_time", 29);
    return FocusUtils.getDurSeconds(saveTime + STEP);
  }

  public int getRestTime() {
    int saveTime = sp.getInt("setting_short_rest", 0);
    return FocusUtils.getDurSeconds(saveTime + STEP);
  }

  public boolean getIsVibrate() {
    return sp.getBoolean("setting_vibrate", true);
  }

  public boolean getIsPreventLockScreen() {
    return sp.getBoolean("setting_prevent_lockscreen", false);
  }

  public boolean getIsPlayTickSound() {
    return sp.getBoolean("setting_tick_sound", false);
  }

  public boolean getIsPlayAlarmSound() {
    return sp.getBoolean("setting_alarm_sound", false);
  }

  public boolean getIsAutoFocus() {
    return sp.getBoolean("setting_auto_focus", false);
  }

  public int getLongRestDelay() {
    return Integer.parseInt(sp.getString("setting_long_rest_delay", "4"));
  }

  public int getLongRestTime() {
    int saveTime = sp.getInt("setting_long_rest", 9);
    return FocusUtils.getDurSeconds(saveTime + STEP);
  }

  public int getFocusTimes() {
    return sp.getInt("focus_times", 0);
  }

  public void setFocusTimes(int times) {
    editor.putInt("focus_times", times).apply();
  }
}
